import type { JCRequestOption } from '../ServiceBase';
import { ServiceBase } from '../ServiceBase';
import { ApiPre } from '../../config';

const urlbase = `/${ApiPre}/${ApiPre}_Hospital`;

export class HospitalService extends ServiceBase {
  /**
   * 获取医院所有方法配置
   */
  GetAllHospitalMethods(option: JCRequestOption = {}) {
    return this.request<bg_hospital_server_method_config[]>(`${urlbase}/GetAllHospitalMethods`, null, option);
  }

  /**
   * 获取医院配置
   */
  GetAllHospitalServerConfigs(option: JCRequestOption = {}) {
    return this.request<HospitalServerConfigVm[]>(`${urlbase}/GetAllHospitalServerConfigs`, null, option);
  }

  /**
   * 根据单位id获取医院配置
   */
  GetHospitalServerConfigByHospitalId(hospitalId: number, option: JCRequestOption = {}) {
    return this.request<HospitalServerConfigVm>(
      `${urlbase}/GetHospitalServerConfigByHospitalId`,
      { hospitalId },
      option
    );
  }

  /**
   * 根据id获取医院配置
   */
  GetHospitalServerConfig(recordId: number, option: JCRequestOption = {}) {
    return this.request<HospitalServerConfigVm>(`${urlbase}/GetHospitalServerConfig`, { recordId }, option);
  }

  /**
   * 保存医院配置
   */
  SaveHospitalServerConfig(model: HospitalServerConfigVm, option: JCRequestOption = {}) {
    return this.request<number>(`${urlbase}/SaveHospitalServerConfig`, { model }, option);
  }

  /**
   * 删除医院配置
   */
  DeleteHospitalServerConfig(recordId: number, option: JCRequestOption = {}) {
    return this.request<boolean>(`${urlbase}/DeleteHospitalServerConfig`, { recordId }, option);
  }

  /**
   * 获取医院信息
   */
  GetUnitInfo(option: JCRequestOption = {}) {
    return this.request<UnitInfo>(`${urlbase}/GetUnitInfo`, null, option);
  }

  SaveOrg(org: OrgVm, option: JCRequestOption = {}) {
    return this.request<number>(`${urlbase}/SaveOrg`, { org }, option);
  }

  SaveOrgManager(manager: OrgManager, option: JCRequestOption = {}) {
    return this.request<boolean>(`${urlbase}/SaveOrgManager`, { manager }, option);
  }

  EnabledOrg(orgId: number, isEnabled: boolean, option: JCRequestOption = {}) {
    return this.request<boolean>(`${urlbase}/EnabledOrg`, { orgId, isEnabled }, option);
  }

  GetOrgById(orgId: number, option: JCRequestOption = {}) {
    return this.request<OrgVm>(`${urlbase}/GetOrgById`, { orgId }, option);
  }

  GetOrgTree(option: JCRequestOption = {}) {
    return this.request<OrgVmTree[]>(`${urlbase}/GetOrgTree`, null, option);
  }

  GetOrgs(option: JCRequestOption = {}) {
    return this.request<OrgVm[]>(`${urlbase}/GetOrgs`, null, option);
  }

  /**
   * 获取单位小程序配置
   */
  GetOrgMiniProgram(orgId: number, option: JCRequestOption = {}) {
    return this.request<OrgMiniProgramModel>(`${urlbase}/GetOrgMiniProgram`, { orgId }, option);
  }

  /**
   * 保存单位小程序配置
   */
  SaveOrgMiniProgram(model: OrgMiniProgramModel, option: JCRequestOption = {}) {
    return this.request<number>(`${urlbase}/SaveOrgMiniProgram`, { model }, option);
  }

  GetDefaultValue(name: string, option: JCRequestOption = {}) {
    return this.request<string>(`${urlbase}/GetDefaultValue`, { name }, option);
  }

  GetDefaultValueOfDefaultVal(name: string, defaultVal: string, option: JCRequestOption = {}) {
    return this.request<string>(`${urlbase}/GetDefaultValueOfDefaultVal`, { name, defaultVal }, option);
  }

  ModifyDefaultValue(name: string, value: string, option: JCRequestOption = {}) {
    return this.request<any>(`${urlbase}/ModifyDefaultValue`, { name, value }, option);
  }

  GetDefaultValueList(configNameList: string[], option: JCRequestOption = {}) {
    return this.request<string>(`${urlbase}/GetDefaultValueList`, { configNameList }, option);
  }

  ModifyDefaultValueList(configData: string, option: JCRequestOption = {}) {
    return this.request<any>(`${urlbase}/ModifyDefaultValueList`, { configData }, option);
  }
}

export class bg_hospital_server_method_config {
  AutoId: number = 0;
  /**
   * 方法名称
   */
  MethodName: string = '';
  /**
   * 调用方法名称
   */
  Method: string = '';
  /**
   * 1:儿保,2:妇保
   */
  Sign: number = 0;
}

export class HospitalServerConfigVm {
  /**
   * 方法配置
   */
  Methods: bg_hospital_server_method[] = [];
  /**
   * 自增ID
   */
  AutoId: number = 0;
  /**
   * 医院ID
   */
  OrgId: number = 0;
  /**
   * 服务器地址
   */
  Server: string = '';
  /**
   * APPID
   */
  AppId: string = '';
  /**
   * 验证码
   */
  AppSecrect: string = '';
  /**
   * 是否为HTTPS
   */
  IsHttps: boolean = false;
  /**
   * 是否有效
   */
  IsEnabled: boolean = false;
  /**
   * 是否使用WebSocket
   */
  IsUseWebSocket: boolean = false;
  /**
   * 请求医院的授权码
   */
  AuthToken: string = '';
  /**
   * 1:儿保,2:妇保
   */
  Sign: number = 0;
}

export class bg_hospital_server_method {
  AutoId: number = 0;
  /**
   * 对应的服务ID
   */
  ServerId: number = 0;
  /**
   * 方法ID
   */
  MethodId: number = 0;
}

export class UnitInfo {
  ImageData: string = '';

  Img: string = '';

  LinkMan: string = '';

  LinkTel: string = '';

  ManagerName: string = '';

  Pwd: string = '';

  RoleId: number = 0;

  AutoId: number = 0;

  OrgName: string = '';

  AreaCode: string = '';
  /**
   * 管辖区域
   */
  AdminAreaCode: string = '';

  Address: string = '';

  Level: string = '';

  ParentId: number | null = null;

  CustomCode: string = '';

  IsEnabled: boolean = false;

  Manager: number = 0;

  UnitCode: string = '';
  /**
   * 字典跟随组织ID
   */
  DictFollowOrgId: number | null = null;
  /**
   * 院区编码
   */
  YuanQuCode: string = '';
  /**
   * 是否允许同步
   */
  IsAllowSync: boolean = false;
  /**
   * 医院别称
   */
  OrgNickName: string = '';
}

export class OrgVm {
  Img: string = '';

  LinkMan: string = '';

  LinkTel: string = '';

  ManagerName: string = '';

  Pwd: string = '';

  RoleId: number = 0;

  AutoId: number = 0;

  OrgName: string = '';

  AreaCode: string = '';
  /**
   * 管辖区域
   */
  AdminAreaCode: string = '';

  Address: string = '';

  Level: string = '';

  ParentId: number | null = null;

  CustomCode: string = '';

  IsEnabled: boolean = false;

  Manager: number = 0;

  UnitCode: string = '';
  /**
   * 字典跟随组织ID
   */
  DictFollowOrgId: number | null = null;
  /**
   * 院区编码
   */
  YuanQuCode: string = '';
  /**
   * 是否允许同步
   */
  IsAllowSync: boolean = false;
  /**
   * 医院别称
   */
  OrgNickName: string = '';
}

export class OrgManager {
  Manager: string = '';

  Pwd: string = '';

  OrgId: number = 0;

  RoleId: number = 0;
}

export class OrgVmTree {
  SubOrgs: OrgVmTree[] = [];

  Img: string = '';

  LinkMan: string = '';

  LinkTel: string = '';

  ManagerName: string = '';

  Pwd: string = '';

  RoleId: number = 0;

  AutoId: number = 0;

  OrgName: string = '';

  AreaCode: string = '';
  /**
   * 管辖区域
   */
  AdminAreaCode: string = '';

  Address: string = '';

  Level: string = '';

  ParentId: number | null = null;

  CustomCode: string = '';

  IsEnabled: boolean = false;

  Manager: number = 0;

  UnitCode: string = '';
  /**
   * 字典跟随组织ID
   */
  DictFollowOrgId: number | null = null;
  /**
   * 院区编码
   */
  YuanQuCode: string = '';
  /**
   * 是否允许同步
   */
  IsAllowSync: boolean = false;
  /**
   * 医院别称
   */
  OrgNickName: string = '';
}

export class OrgMiniProgramModel {
  AutoId: number = 0;

  OrgId: number = 0;

  CollectiveMiniProgram: string = '';

  CollectivePhotoJson: string = '';
}
